#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000005;
const int mod = 1e9 + 7;
int nex[MAX];

int dp[MAX];
string p;
long long fpow(int a, int x) {
  long long ans = 1;
  while (x) {
    if (x & 1)
      ans = ans * a % mod;
    a = (1LL * a * a) % mod;
    x >>= 1;
  }
  return ans;
}

long long inv(int a) { return fpow(a, mod - 2); }
long long divide(int a, int b) { return 1LL * a * inv(b) % mod; }

void kmp(string p, int n) {
  nex[1] = 0; // 为了方便，是从1开始。
  for (int i = 2; i <= n; i++) {
    int j = nex[i - 1];
    while (j > 0) {
      if (p[i] == p[j + 1]) {
        nex[i] = j + 1;
        break;
      } else
        j = nex[j];
    }
    if (j == 0) {
      if (p[i] == p[1])
        nex[i] = 1;
      else
        nex[i] = 0;
    }
  }
}

// 需要优化。
int d[MAX][2];
int trans_to(int i, int j) { // j=0或者1
  if (d[i][j] != -1)
    return d[i][j];
  if (p[i + 1] - '0' == j)
    return d[i][j] = i + 1;
  if (i == 0)
    return d[i][j] = 0;
  return d[i][j] = trans_to(nex[i], j);
}
long long a[MAX], b[MAX];
int main() {

  int n;
  cin >> n;
  for (int i = 0; i <= n; i++)
    d[i][0] = d[i][1] = -1;
  cin >> p;
  p = " " + p;
  kmp(p, n);
  a[0] = 1, b[0] = 0;
  a[1] = 1, b[1] = 2;
  for (int i = 2; i <= n; i++) {
    // dp[i+1]=2*dp[i]-dp[j]-2
    // j=trans_to(i-1,(p[i]-'0')^1)
    a[i] =
        (2 * a[i - 1] % mod + mod - a[trans_to(i - 1, (p[i] - '0') ^ 1)]) % mod;
    b[i] =
        (2 * b[i - 1] % mod + mod - b[trans_to(i - 1, (p[i] - '0') ^ 1)] + 2) %
        mod;
  }
  cout << divide(b[n], a[n]) << endl;
}